package servlet

import (
	"gdmin/model"
	"github.com/cloudwego/hertz/pkg/app"
	"net/http"
)

type LogResp struct {
	model.Log
	UserName string `json:"userName,omitempty" gorm:"-"`
}
type LoginResp struct {
	Token string `json:"token"`
}

type Userinfo struct {
	Id         int             `json:"-"`
	Role       []string        `json:"role"`
	Menus      []model.ResMenu `json:"menus"`
	RoleIds    []int           `json:"roleIds"`
	Phone      string          `json:"phone"`
	Name       string          `json:"name"`
	Email      string          `json:"email"`
	Avatar     string          `json:"avatar"`
	MainDeptId int             `json:"mainDeptId"`
	DeptIds    []int           `json:"deptIds"`
}

// swagger:response RoleResp
type ResMenuResp struct {
	model.ResMenu
	// 上级菜单名称
	ParentMenuName string `json:"parentMenuName,omitempty" gorm:"-"`
	// 绑定的接口id集合
	BindApiIds []int `json:"bindApiIds,omitempty" gorm:"-"`
	BindBtnIds []int `json:"bindBtnIds" gorm:"-"`

	BindApi    []model.ResApi    `json:"bindApis" gorm:"-"`
	BindButton []model.ResButton `json:"bindButtons" gorm:"-"`
}

// swagger:response ResButtonResp
type ResButtonResp struct {
	model.ResButton
	MenuName string `json:"menuName,omitempty" gorm:"-"`
}

// swagger:response ResApiResp
type ResApiResp struct {
	model.ResApi
}

// swagger:response DictResp
type DictResp struct {
	model.Dict

	// 上级名称
	ParentName string `json:"parentName,omitempty" gorm:"-"`
}

// swagger:response DictItemResp
type DictItemResp struct {
	model.DictItem
	DictName string `json:"dictName,omitempty" gorm:"-"`
}

// swagger:response UserResp
type UserResp struct {
	model.User
	Roles      []model.Role `json:"roles" gorm:"-"`
	MainDeptId int          `json:"mainDeptId" gorm:"-"`
	DeptIds    []int        `json:"deptIds" gorm:"-"`
}

// swagger:response RoleResp
type RoleResp struct {
	model.Role
	Menus []model.ResMenu `json:"menus" gorm:"-"`
}

// swagger:response DeptResp
type DeptResp struct {
	model.Dept
	// 上级部门名称
	ParentDeptName string `json:"parentDeptName" gorm:"-"`
	// 子级部门
	Childs []*DeptResp `json:"childs" gorm:"-"`
}

const (
	ERROR   = 40001
	SUCCESS = 20000
)

// swagger:response Resp
type Resp struct {
	Code int         `json:"code"`
	Msg  string      `json:"message"`
	Data interface{} `json:"data"`
}

func Ok(ctx *app.RequestContext) {
	Result2(SUCCESS, map[string]interface{}{}, "操作成功", ctx)
}

func OkWithData(ctx *app.RequestContext, data interface{}) {
	Result2(SUCCESS, data, "操作成功", ctx)

}

func Result2(code int, data interface{}, msg string, ctx *app.RequestContext) {
	ctx.JSON(http.StatusOK, Resp{
		code,
		msg,
		data,
	})
}
func FailWithMessage(message string, ctx *app.RequestContext) {
	Result2(ERROR, map[string]interface{}{}, message, ctx)
}

func FailWithDetailed(data interface{}, message string, ctx *app.RequestContext) {
	Result2(ERROR, data, message, ctx)
}
